package com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bean.ArticleContext;
import com.bean.VideoContext;
import com.bean.WeiboContext;
import com.dao.CollectMessageDao;
import com.service.CollectMessageService;
import com.util.LoggerUtil;
@Component
public class CollectMessageServiceImpl implements CollectMessageService{
	public static Logger logger=Logger.getLogger(CollectMessageServiceImpl.class);
	@Autowired
	private CollectMessageDao collectMessageDao;

	@Override
	public Map<String, Object> insertWeibo(String userId, String oldId,JSONObject logs) {
		return collectMessageDao.insertWeibo(userId, oldId,logs);
	}

	@Override
	public Map<String, Object> insertVideo(String userId, String oldId,JSONObject logs) {
		return collectMessageDao.insertVideo(userId, oldId,logs);
	}

	@Override
	public Map<String, Object> insertArticle(String userId, String oldId,JSONObject logs) {
		return collectMessageDao.insertArticle(userId, oldId,logs);
	}

	@Override
	public Map<String, Object> selectListCollectWeibo(String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			List<WeiboContext> weiboContexts=collectMessageDao.selectListCollectWeibo(userId);
			if(weiboContexts.size()>0){
				map.put("result", "success");
				map.put("rows", weiboContexts);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	@Override
	public Map<String, Object> selectListCollectVideo(String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			List<VideoContext> weiboContexts=collectMessageDao.selectListCollectVideo(userId);
			if(weiboContexts.size()>0){
				map.put("result", "success");
				map.put("rows", weiboContexts);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	@Override
	public Map<String, Object> selectListCollectArticle(String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			List<ArticleContext> weiboContexts=collectMessageDao.selectListCollectArticle(userId);
			if(weiboContexts.size()>0){
				map.put("result", "success");
				map.put("rows", weiboContexts);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	
	
}
